from django.db import models
from django.contrib.auth.models import User,AbstractUser
from django.db.models.deletion import CASCADE, SET_DEFAULT, SET_NULL

# Create your models here.
'''
class MyUser(AbstractUser):
  some_extra_data = models.CharField(max_length=100, blank=True)
'''
#用户附加信息表class MyUser(AbstractUser):
class useradd(models.Model):
    user = models.OneToOneField(User,on_delete=CASCADE)
    facade = models.CharField(max_length=256,verbose_name="头像",default='53a9b502494cf.svg')
    Background = models.CharField(max_length=16,verbose_name="背景",default='#e0faff')
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    address = models.CharField(max_length=256,verbose_name="钱包")
    balance = models.FloatField(verbose_name="余额",default=0)#decimal_places=7,
    freeze = models.FloatField(verbose_name="冻结",default=0)
    growthan = models.FloatField(verbose_name="掘金加成",default=0)
    bearval = models.FloatField(verbose_name="掘金总收益",default=0)
    dognum = models.IntegerField(verbose_name="狗数",default=0)
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")

    class Meta:
        ordering = ('created',)

#狗信息表
class Dog(models.Model):
    desc = models.CharField(max_length=256,verbose_name="简介")
    facade = models.CharField(max_length=256,verbose_name="头像",default='53a9b502494cf.svg')
    Background = models.CharField(max_length=16,verbose_name="背景",default='#e0faff')
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    generation = models.IntegerField(verbose_name="代数",default=0)
    weight = models.FloatField(verbose_name="体重",default=0)#decimal_places=7,
    grow = models.FloatField(verbose_name="成长",default=1)
    growthan = models.FloatField(verbose_name="投喂增长比",default=0)
    bearval = models.FloatField(verbose_name="生育值",default=1.2)
    bearnum = models.IntegerField(verbose_name="生育次数",default=0)
    digoldval = models.FloatField(verbose_name="掘金值",default=0)
    dignum = models.IntegerField(verbose_name="掘金次数",default=0)
    digsum = models.FloatField(verbose_name="掘金总收益",default=0)#decimal_places=7,
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")

    class Meta:
        ordering = ('created',)

#用户狗关系表
class userdog(models.Model):
    user = models.ForeignKey(User,on_delete=CASCADE)
    dog = models.ForeignKey(Dog,on_delete=CASCADE)
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")

    class Meta:
        ordering = ('created',)

#喂养记录
class dogfeed(models.Model):
    user = models.ForeignKey(User,on_delete=CASCADE)
    dog = models.ForeignKey(Dog,on_delete=CASCADE)
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    money  = models.FloatField(verbose_name="金额",default=0)
    hash = models.CharField(max_length=256,verbose_name="hash")
    weightgrow  = models.FloatField(verbose_name="体重增加",default=0)#decimal_places=7,
    growgrow  = models.FloatField(verbose_name="成长增加",default=0)#decimal_places=7,
    beargrow  = models.FloatField(verbose_name="生育增加",default=0)#decimal_places=7,
    diggrow  = models.FloatField(verbose_name="掘金增加",default=0)#decimal_places=7,
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")

    class Meta:
        ordering = ('created',)

#掘金记录
class digrecord(models.Model):
    user = models.ForeignKey(User,on_delete=CASCADE)
    dog = models.ForeignKey(Dog,on_delete=CASCADE)
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    money  = models.FloatField(verbose_name="金额",default=0)
    hash = models.CharField(max_length=256,verbose_name="hash")
    diggrow  = models.FloatField(verbose_name="掘金增加",default=0)#decimal_places=7,
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")

    class Meta:
        ordering = ('created',)

#族谱记录
class fromrecord(models.Model):
    doga = models.IntegerField(verbose_name="父亲",default=0)
    dogb = models.IntegerField(verbose_name="母亲",default=0)
    dogc = models.IntegerField(verbose_name="新生",default=0)
    type =  models.CharField(max_length=16,verbose_name="类型",default='生育')#合成
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    money  = models.FloatField(verbose_name="金额",default=0)
    hash = models.CharField(max_length=256,verbose_name="hash")
    diggrow  = models.FloatField(verbose_name="掘金增加",default=0)#decimal_places=7,
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")

    class Meta:
        ordering = ('created',)

#集市信息
class fairinfo(models.Model):
    dog = models.ForeignKey(Dog,on_delete=CASCADE)
    owner = models.ForeignKey(User,on_delete=CASCADE)
    type =  models.CharField(max_length=16,verbose_name="类型",default='市集')#市集2，鹊桥3，挑战4，合成5
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    money  = models.FloatField(verbose_name="金额",default=0)
    fairid = models.IntegerField(verbose_name="交易id",default=0)
    acceptid = models.IntegerField(verbose_name="购买人id",default=0)
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")
    updated = models.DateTimeField(auto_now_add=True,verbose_name="更新时间")

    class Meta:
        ordering = ('created',)

#交易信息
class fairrecord(models.Model):
    ownerhash = models.CharField(max_length=256,verbose_name="发起人hash钱包")
    accephash = models.CharField(max_length=256,verbose_name="到账人hash钱包")
    type =  models.CharField(max_length=16,verbose_name="类型",default='市集')#市集，鹊桥，挑战，合成
    status = models.CharField(max_length=5,verbose_name="状态",default='A')
    money  = models.FloatField(verbose_name="金额",default=0)
    fairid = models.IntegerField(verbose_name="交易id",default=0)
    acceptid = models.IntegerField(verbose_name="购买人id",default=0)
    created = models.DateTimeField(auto_now_add=True,verbose_name="出生时间")
    updated = models.DateTimeField(auto_now_add=True,verbose_name="更新时间")

    class Meta:
        ordering = ('created',)